package com.s7_widgets;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.SeekBar;

import androidx.appcompat.app.AppCompatActivity;

import com.s7.widget.listener.OnDashBoardListener;
import com.s7.widget.test.DashboardView;
import com.s7.widget.test.TempHumView;
import com.s7.widget.widget.DashBoard;


public class DashBoardActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener,
        OnDashBoardListener, View.OnClickListener {

    private DashboardView dashboardView;
    private SeekBar seekBar;
    private DashBoard dashBoard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dash_board);

        dashboardView = findViewById(R.id.dash_board_dashboard);
        seekBar = findViewById(R.id.dash_board_dashboard_seek);

        dashBoard = findViewById(R.id.dash_board_dash);
        dashBoard.setProgress(new int[]{0xFF0FBFF6, 0xFF0FBFF6, 0xFF0FBFF6, 0xFF3051FC, 0xFF3051FC,
                0xFF3D5575, 0xFF5124E8, 0xFF5124E8, 0xFFDE0E89, 0xFFDE0E89, 0xFFDE0E89});
        dashBoard.setOnListener(this);
        seekBar.setOnSeekBarChangeListener(this);
        findViewById(R.id.dash_board_btn1).setOnClickListener(this);
        findViewById(R.id.dash_board_btn2).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dash_board_btn1:
                dashBoard.setDividingRule(0, 240, 12, 3, DashBoard.INTERVAL_ODD, "℃");
                break;
            case R.id.dash_board_btn2:
                dashBoard.setDividingRule(0, 2200, 11, 3, DashBoard.INTERVAL_ODD, "w");
                break;
        }
    }


    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        dashboardView.setPercent(progress);
        float current = progress  * 240 / 100;
        Log.d("进度", "当前温度：" + current);
        dashBoard.setCurrent(current);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onDashBoard(DashBoard view, float current) {
        Log.e("activity 中选中值回调", String.valueOf(current));
    }

}
